package com.lancoo.znbkxx.teacher.aibkGenerateTestPaper.aibkGenerateDialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkGenerateTestPaper.aibkLineChart.LanguageLineChartManager
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.Klg
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.TopicLanguageKlgInfor
import kotlinx.android.synthetic.main.aibk_dialog_specific_grammar_analysis.IvCloseDialog
import kotlinx.android.synthetic.main.aibk_dialog_specific_language_analysis.*

class DialogSpecificLanguageAnalysis(
        context: Context?,
        val activity: AppCompatActivity,
        val pos: Int,
        val topicLanguageKlgInfor: TopicLanguageKlgInfor
) : Dialog(context!!, R.style.CustomDialog) {
    /**
     * 提交按钮
     */
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.aibk_dialog_specific_language_analysis)
        window!!.setGravity(Gravity.BOTTOM) //设置弹窗右对齐
        window!!.setWindowAnimations(R.style.MyDialogBottomTranslate) //设置动画效果

        val wl = window!!.attributes
        //以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        onWindowAttributesChanged(wl)
        setCanceledOnTouchOutside(false)

        //初始化界面数据
        initView()
    }

    /**
     * 初始化界面控件的显示数据
     */
    private fun initView() {

        //关闭dialog
        IvCloseDialog.setOnClickListener {
            dismiss()
        }

        TvAbilityPart

        //重组数据
        var inforPartAll :ArrayList<Klg> = ArrayList()
        var inforPartA :ArrayList<Klg> = ArrayList()
        var inforPartB :ArrayList<Klg> = ArrayList()
        var inforPartC :ArrayList<Klg> = ArrayList()
        val klgListSize = topicLanguageKlgInfor.KlgList.size
        for(i in 0 until klgListSize){
            val importCode = topicLanguageKlgInfor.KlgList[i].ImportCode
            val isstudy = topicLanguageKlgInfor.KlgList[i].Isstudy
            if(importCode == "A"&&isstudy){
                inforPartA.add(topicLanguageKlgInfor.KlgList[i])
                inforPartAll.add(topicLanguageKlgInfor.KlgList[i])
            }
        }
        for(i in 0 until klgListSize){
            val importCode = topicLanguageKlgInfor.KlgList[i].ImportCode
            val isstudy = topicLanguageKlgInfor.KlgList[i].Isstudy
            if(importCode == "B"&&isstudy){
                inforPartB.add(topicLanguageKlgInfor.KlgList[i])
                inforPartAll.add(topicLanguageKlgInfor.KlgList[i])
            }
        }
        for(i in 0 until klgListSize){
            val importCode = topicLanguageKlgInfor.KlgList[i].ImportCode
            val isstudy = topicLanguageKlgInfor.KlgList[i].Isstudy
            if(importCode == "C"&&isstudy){
                inforPartC.add(topicLanguageKlgInfor.KlgList[i])
                inforPartAll.add(topicLanguageKlgInfor.KlgList[i])
            }
        }

        Log.e("aavvccbb", "==AAA===importCodeSize========" + inforPartA.size)
        Log.e("aavvccbb", "==BBB===importCodeSize========" + inforPartB.size)
        Log.e("aavvccbb", "==CCCC===importCodeSize========" + inforPartC.size)

        //展示图表
        //显示曲线图表1
        val lineChartManager1 = LanguageLineChartManager(LineChartAnalysis1)
        lineChartManager1.showLineChart(inforPartA, "我的分数", activity.resources.getColor(R.color.lineChartLineBlue))
        lineChartManager1.addLine(inforPartA, "系统及格线", activity.resources.getColor(R.color.lineChartLineGreen))
        //设置曲线填充色 以及 MarkerView
        val drawable1 = activity.resources.getDrawable(R.drawable.aibk_fade_blue)
        lineChartManager1.setChartFillDrawable(drawable1)
        lineChartManager1.setMarkerView(activity, inforPartA,1)

        //显示曲线图表2
        val lineChartManager2 = LanguageLineChartManager(LineChartAnalysis2)
        //展示图表
        lineChartManager2.showLineChart(inforPartB, "我的分数", activity.resources.getColor(R.color.lineChartLineOrange))
        lineChartManager2.addLine(inforPartB, "系统及格线", activity.resources.getColor(R.color.lineChartLineGreen))
        //设置曲线填充色 以及 MarkerView
        val drawable2= activity.resources.getDrawable(R.drawable.aibk_fade_orange)
        lineChartManager2.setChartFillDrawable(drawable2)
        lineChartManager2.setMarkerView(activity, inforPartB,2)

        //显示曲线图表3
        val lineChartManager3 = LanguageLineChartManager(LineChartAnalysis3)
        //展示图表
        lineChartManager3.showLineChart(inforPartC, "我的分数", activity.resources.getColor(R.color.lineChartLineRed))
        lineChartManager3.addLine(inforPartC, "系统及格线", activity.resources.getColor(R.color.lineChartLineGreen))
        //设置曲线填充色 以及 MarkerView
        val drawable3 = activity.resources.getDrawable(R.drawable.aibk_fade_red)
        lineChartManager3.setChartFillDrawable(drawable3)
        lineChartManager3.setMarkerView(activity, inforPartC,3)

        //显示底部文字
        TvCkzsd.text = "常考知识点("+inforPartA.size+")"
        TvCckzsd.text = "次常考知识点("+inforPartB.size+")"
        TvBckzsd.text = "不常考知识点("+inforPartC.size+")"
        TvBottomMessage.text = "上图显示已复习知识点，剩余未复习知识点"+(klgListSize-inforPartA.size-inforPartB.size-inforPartC.size)+"个未展示。";

    }

//    private var clickDialogListener: onClickDialogListener? = null
//
//    /*
//   * 设置答题卡题号点击事件
//   * */
//    interface onClickDialogListener {
//        fun onClickCancel()//不再提醒
//        fun onClickQuit()//确认
//    }
//
//    fun setClickDialogListener(clickDialogListener: onClickDialogListener?) {
//        this.clickDialogListener = clickDialogListener
//    }
}